<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
	String keywords = input.getDesc("keywords", "-1").trim().replaceAll(" ", "").replace("%", "\\%").replace("_", "\\_");
	if("".equals(keywords)) {
		msg = new Message(30041, "请键入搜素关键字");
		Tools.encryptPrint(out, msg);
		return;
	}
	List<Map> templates =  QBuilder.db("basedb").select("new map(id as template_id, template_name as title, template_type as detail)").from("visit_template").where(new Where("status = ", STATUS_ENABLE).and("category=0").and("template_name like '%" + keywords + "%' or template_type like '%" + keywords + "%'" )).query().getResultObj();
	List<Integer> myTemplates =  QBuilder.db("basedb").select("oid").from("visit_template").where(new Where("status = ", STATUS_ENABLE).and("category=", 1).and("uid=", token.getUid())).query().getResultObj();
	for (Map map:templates) {
		map.put("added", 0);
		Integer id = (Integer)map.get("template_id");
		if (myTemplates.contains(id))
			map.put("added", 1);
	}
	if (isEmpty(templates)) {
		msg = new Message(30041, "没有更多了");
	}
	msg.put("data", templates);
	Tools.encryptPrint(out, msg);
%>